package cn.source.system.controller;

import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.core.page.TableDataInfo;
import cn.source.common.enums.BusinessType;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.system.domain.DeyuArticle;
import cn.source.system.service.IDeyuArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资讯信息Controller
 *
 * @author deyucare.com
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/deyu/deyuArticle")
public class DeyuArticleController extends BaseController
{
    @Autowired
    private IDeyuArticleService deyuArticleService;

    /**
     * 查询资讯信息列表
     */
    @PreAuthorize("@ss.hasPermi('deyu:deyuArticle:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeyuArticle deyuArticle)
    {
        startPage();
        List<DeyuArticle> list = deyuArticleService.selectDeyuArticleList(deyuArticle);
        return getDataTable(list);
    }

    /**
     * 获取资讯信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(deyuArticleService.selectDeyuArticleById(id));
    }

    /**
     * 新增资讯信息
     */
    @PreAuthorize("@ss.hasPermi('deyu:deyuArticle:add')")
    @Log(title = "资讯信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeyuArticle deyuArticle)
    {
        return toAjax(deyuArticleService.insertDeyuArticle(deyuArticle));
    }

    /**
     * 修改资讯信息
     */
    @PreAuthorize("@ss.hasPermi('deyu:deyuArticle:edit')")
    @Log(title = "资讯信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeyuArticle deyuArticle)
    {
        return toAjax(deyuArticleService.updateDeyuArticle(deyuArticle));
    }

    /**
     * 删除资讯信息
     */
    @PreAuthorize("@ss.hasPermi('deyu:deyuArticle:remove')")
    @Log(title = "资讯信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deyuArticleService.deleteDeyuArticleByIds(ids));
    }

    /**
     * 导出资讯信息列表
     */
    @PreAuthorize("@ss.hasPermi('deyu:deyuArticle:export')")
    @Log(title = "资讯信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeyuArticle deyuArticle)
    {
        List<DeyuArticle> list = deyuArticleService.selectDeyuArticleList(deyuArticle);
        ExcelUtil<DeyuArticle> util = new ExcelUtil<DeyuArticle>(DeyuArticle.class);
        util.exportExcel(response, list, "资讯信息数据");
    }
}
